using System;
using Microsoft.Practices.ServiceLocation;

namespace Caramel
{
	public static class LocalStorage
	{
		private static ILocalStorage Default = new ThreadLocalStorage();

		public static Func<ILocalStorage> GetCurrent = 
			() => 
			{
				try
				{
					return ServiceLocator.Current.GetInstance<ILocalStorage>();
				}
				catch
				{
					return LocalStorage.Default;
				}
			};

		public static ILocalStorage Current
		{
			get
			{
				return LocalStorage.GetCurrent();
			}
		}
	}
}
